import { getArticleApi, delArticleApi } from "@/apis/article";
import type { FilterArticleParams, Article } from "@/apis/article";
export const useArticle = (
  params: FilterArticleParams = {
    page: 1,
    per_page: 4,
    begin_pubdate: null,
    end_pubdate: null,
    status: null,
    channel_id: null
  }
) => {
  const [articleList, setArticleList] = useState({
    list: [] as Article[],
    count: 0,
  });

  useEffect(() => {
    async function fetchArticleList() {
      const res = await getArticleApi(params);
      const { results, total_count } = res.data;
      setArticleList({
        list: results,
        count: total_count,
      });
    }
    fetchArticleList();    
  }, [params]);

  const delArticle = useCallback(async (article: Article) => {
    const res = await delArticleApi(article.id)
    return res
  }, [])
  return { articleList, delArticle }
};
